<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>材料信息管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css" media="all">
    <style>
        .mask .layui-form-select .layui-input{padding-right: 0;}
        .layui-form-label{height: 20px;}
        .layui-input-inline{width: 80%;}
        .layui-form-item{margin-bottom: 8px;}
        .masksx .forms{padding-left: 0;}
        .forms form{text-align: center;}
        .forms form .layui-form-item{display: inline-block;width: 300px;}
    </style>
</head>


<body>
<form class="layui-form layui-form-pane" id="form_7grid" action="" lay-filter="hetong">
    <div class="formTop">
        <div class="layui-inline layui-col-lg3 layui-col-sm3 layui-col-xs3">
            <div class="layui-input-inline" style="margin-right: 0;">
                <input type="text" name="username" lay-verify="required" placeholder="材料名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline layui-col-lg3 layui-col-sm3 layui-col-xs3">
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="test-limit3" placeholder="请选择开始日期">
                <div class="icons">
                </div>
            </div>
        </div>
        <div class="layui-inline layui-col-lg3 layui-col-sm3 layui-col-xs3">
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="test-limit4" placeholder="请选择结束日期">
                <div class="icons">
                </div>
            </div>
        </div>
        <div class="layui-inline  layui-col-lg3 layui-col-sm3 layui-col-xs3 anniu">
            <button class="layui-btn chaxun" type="button" onclick="query()">查询</button>
            <button class="layui-btn layui-btn-normal quanxian" type="button" style="background-color: #ff8f3b;" onclick="addTo()" QX="api/material/addMaterial.do">添加</button>
        </div>

    </div>
    <table id="demo" lay-filter="test"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-danger layui-btn-sm quanxian" lay-event="detail" QX="api/material/updateMater.do">编辑</a>
        <a class="layui-btn layui-btn-sm" lay-event="edit">查看</a>
        <a class="layui-btn layui-btn-danger layui-btn-sm quanxian" lay-event="del" QX="api/material/delMater.do">删除</a>

    </script>
    <!--<script type="text/html" id="titleTpl">-->

    <!--<span>{{times(1510635999999)}}</span>-->
    <a class="dayin" type="button" id="dlink"  style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>


    <!--</script>-->
</form>
<div id="demo7"></div>
<div class="mask">
    <div class="masksx">
        <div class="title"><span class="titleL">添加材料</span><span class="close">×</span></div>
        <div class="forms">
            <form class="layui-form dynamic" action="" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>材料类型：</label>
                    <div class="layui-input-inline" style="width: 160px;">
                        <select name="Mat_type" lay-search="" class="gongliaoon">

                        </select>
                        <input type="text" name="securid_Compid" placeholder="" autocomplete="off" class="layui-input yinchang">
                    </div>
                </div>

            <div class="layui-form-item">
                <label class="layui-form-label">材料名称<span class="maohao">：</span></label>
                <div class="layui-input-block">
                    <input type="text" name="mat_name" lay-verify="required" autocomplete="off" placeholder="请输入材料名称" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">材料规格<span class="maohao">：</span></label>
                <div class="layui-input-block">
                    <input type="text" name="mat_spec" lay-verify="required" autocomplete="off" placeholder="请输入材料规格" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">材料简称<span class="maohao">：</span></label>
                <div class="layui-input-block">
                    <input type="text" name="mat_shortname" lay-verify="required" autocomplete="off" placeholder="请输入材料简称" class="layui-input" value="">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">材料价格<span class="maohao">：</span></label>
                <div class="layui-input-block">
                    <input type="number" name="mat_price" lay-verify="required" autocomplete="off" placeholder="请输入材料价格" class="layui-input" value="" step="0.01">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">材料税率<span class="maohao">：</span></label>
                <div class="layui-input-block">
                    <input type="number" name="mat_tax" lay-verify="required" autocomplete="off" placeholder="请输入材料税率" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">计量单位<span class="maohao">：</span></label>
                <div class="layui-input-block">
                    <input type="text" name="mat_bit" lay-verify="required" autocomplete="off" placeholder="请输入材料单位" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">材料运费<span class="maohao">：</span></label>
                <div class="layui-input-block">
                    <input type="number" name="mat_freight" lay-verify="required" autocomplete="off" placeholder="请输入材料运费" class="layui-input" value="">
                </div>
            </div>
            <input type="hidden" name="state" value="0" id="state"/>
            <input type="hidden" name="mat_id" id="mat_id"/>


            <div class="_submit">
                <button class="layui-btn tijiao" lay-submit lay-filter="_subm">提交</button>
                <button class="layui-btn " type="reset">重置</button>
            </div>

        </form>
        </div>
    </div>

</div>


<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>
<script>

    function query() {
        layui.use(['form', 'layedit', 'laydate','table','element'], function() {
            var form = layui.form
                , table = layui.table;
            var pronName=$("[name='username']").val();
            var begintime=$('#test-limit3').val();
            var endtime=$('#test-limit4').val();

            if(!AntiSqlValid(pronName)){
                if(lbq('api/material/loadMaterList.do')){
                    API.materialInformAdmin({'mat_name':pronName,'begintime':begintime,'endtime':endtime,'p':getCookie('yanzheng')})
                }

            }else {
                layer.msg('请勿输入特殊符号');
            };


        })

    };

    function addTo() {
        layui.use(['form', 'layedit', 'laydate','table','element'], function() {
            var form = layui.form
                , table = layui.table;

            $('.mask').show();
            $('.mask input').val('');
            alertoff();
            _false=true;
            sessionStorage.bianji='tianjia'

        })

    }
    var _false=true;

    layui.use(['form', 'layedit', 'laydate','table','element','laypage'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table=layui.table
            ,laypage=layui.laypage
            ,element=layui.element;
        jiazais();

        $('.dynamic').attr('action',urls+'/api/material/addMaterial.html');

        $('.close').click(function () {     //遮罩层隐藏
            $('.mask').hide();
        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        if(lbq('api/material/loadMaterList.do')) {

            API.materialInformAdmin({'p': getCookie('yanzheng')}, function () {
                //console.log(arguments);
                xiala = arguments[0].Feeding;
                //console.log(xiala)
                //材料类型下拉加载
                $("[name='Mat_type']").html('')
                for (var i = 0; i < xiala.length; i++) {
                    $("[name='Mat_type']").append('<option value="' + xiala[i].p_value + '">' + xiala[i].p_name + '</option>');
                }
                form.render();//渲染下拉
            });
        }
        dayintishi('.dayin');


        $('.dynamic').attr('action',urls+'/api/comp/inComp.do')

//
        //前后若干天可选，这里设置不能选过去的日期      最远可选1000天之后
        panduanshijiantow('#test-limit3','#test-limit4',1000,1000,'.chaxun');     //查询 开始结束时间判断
        inputs();
        //判断数字是否为负数;
        $(document).on('blur','[type="number"]',function () {
            if($(this).val()<0){
                layer.msg('数量不能小于0');
                $(this).val(0);
            }
        })


        $('#state').val('0');       //隐藏域声明
        //监听工具条
        table.on('tool(test)', function(obj){ //注<span class="maohao">：</span>tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'detail'){ //编辑
                //do somehing
                //console.log(obj)
                sessionStorage.bianji='bianji';
                $('.mask').show();
                $('.titleL').html('编辑材料');

                var datas=obj.data;
                datas.mat_freight=parseInt(datas.mat_freight);
                //console.log($.type(datas.mat_freight))
                if(!!isNaN(datas.mat_freight)){
                    datas.mat_freight=0;
                }
                /------------->数据赋值/
                $('.titles_T').html('查看材料');
                $('[name=Mat_type]').val(datas.mat_type);
                $("[name='mat_name']").val(datas.mat_name);
                $("[name='mat_spec']").val(datas.mat_spec);
                $("[name='mat_shortname']").val(datas.mat_shortname);
                $("[name='mat_price']").val(datas.mat_price);
                $("[name='mat_tax']").val(datas.mat_tax);
                $("[name='mat_bit']").val(datas.mat_bit);
                $("[name='mat_freight']").val(datas.mat_freight);

                sessionStorage.mat_id=datas.mat_id;
                /<------------数据赋值/
                //console.log($("[name='mat_tax']").val() )

                form.render();
                alertoff();
            } else if(layEvent === 'del'){ //删除
                layer.confirm('确认删除？', function(index){
                    //console.log(obj)

                    ajaxs('/api/material/delMater.do','post',{'mat_id':obj.data.mat_id,'p':getCookie('yanzheng')},function (data) {
                        //向服务端发送删除指令

                        //console.log(data)
                        if(data.code==0){
                            layer.msg(data.msg);
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            layer.close(index);
                        }else{
                            layer.msg(data.msg);
                            setTimeout(function () {
                                location.reload();
                            },800)
                        }
                    })

                });
            } else if(layEvent === 'edit'){ //查看
                //do something
                var datas=obj.data;
                //console.log(datas)

                $('.dynamic').attr('action',urls+'/api/material/updateMater.html')
                /*------------->数据赋值*/
                $('.titleL').html('查看材料');
                $('[name=Mat_type]').val(datas.mat_type);
                $("[name='mat_name']").val(datas.mat_name);
                $("[name='mat_spec']").val(datas.mat_spec);
                $("[name='mat_shortname']").val(datas.mat_shortname);
                $("[name='mat_price']").val(datas.mat_price);
                $("[name='mat_tax']").val(datas.mat_tax);
                $("[name='mat_bit']").val(datas.mat_bit);
                $("[name='mat_freight']").val(parseInt(datas.mat_freight));
                $('#mat_id').val(datas.mat_id);       //隐藏域声明
                form.render();
                /*<------------数据赋值*/
                                   //遮罩层出现

                switch (datas.mat_type){
                    case 1:
                        datas.mat_type='上覆';
                        break;
                    case 2:
                        datas.mat_type='管材';
                        break;
                    case 3:
                        datas.mat_type='井盖';
                        break;
                    case 4:
                        datas.mat_type='特殊';
                        break;
                }
                $('[name="securid_Compid"]').val(datas.mat_type)
                alerton();
            }
        });

        //提交监听提交
        form.on('submit(_subm)', function(data){

            //console.log(data.field,'<-----------------') //当前容器的全部表单字段，名值对形式<span class="maohao">：</span>{name: value}
            data.field.p=getCookie('yanzheng');
            formAlertAjax('/api/material/addMaterial.do',data.field,'.tijiao')
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //修改监听
        form.on('submit(_subm)', function(data){

            //console.log(data.field,'<-----------------') //当前容器的全部表单字段，名值对形式<span class="maohao">：</span>{name: value}
            data.field.p=getCookie('yanzheng');
            if(sessionStorage.bianji=='bianji'){
                data.field.mat_id=sessionStorage.mat_id;

                formAlertAjax('/api/material/updateMater.do',data.field,'.tijiao')
            }else{

                formAlertAjax('/api/material/addMaterial.do',data.field,'.tijiao')
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    })

</script>
</body>
</html>